package com.hehui.partimejob.activity.ques;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.webkit.WebView;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.hehui.partimejob.BaseActivity;
import com.hehui.partimejob.R;
import com.hehui.partimejob.uitls.LiveDataBus;
import com.hehui.partimejob.uitls.MyUtil;

import java.util.ArrayList;

public class AddQuesActivity extends BaseActivity {
    private EditText title;
    private EditText welcome;
    private TextView create;

    private TextView quesTitle;
    private EditText title2;
    private TextView welcomeTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

//        开始流程
        create.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (!MyUtil.checkEditViewHasValue(AddQuesActivity.this.title, welcome)) {
                    Log.d(TAG, "onClick: 1111");
                    Toast.makeText(AddQuesActivity.this, "请输入完整内容", Toast.LENGTH_SHORT).show();
                    return;
                }
                Intent intent = new Intent(AddQuesActivity.this, EditQuesActivity.class);
                intent.putExtra("title", AddQuesActivity.this.title.getText().toString());
                intent.putExtra("welcome", welcome.getText().toString());
                startActivity(intent);
            }
        });

//        编辑欢迎语
        String titleStr = getIntent().getStringExtra("title");
        String welStr = getIntent().getStringExtra("wel");
        if (!TextUtils.isEmpty(titleStr)) {
            this.title.setText(titleStr);
            this.welcome.setText(welStr);
            getNavView().setTitle(getString(R.string.ques_begin));
            this.create.setText(R.string.save);
            this.create.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ArrayList<String> list = new ArrayList<>();
                    list.add(title.getText().toString());
                    list.add(welcome.getText().toString());
                    LiveDataBus.getInstance().with("head", ArrayList.class).setValue(list);
                    finish();
                }
            });
        }


//        编辑结束语
        String end = getIntent().getStringExtra("end");
        if (!TextUtils.isEmpty(end)) {
            getNavView().setTitle(R.string.ques_end);
            this.quesTitle.setVisibility(View.GONE);
            this.title2.setVisibility(View.GONE);
            this.welcomeTitle.setVisibility(View.GONE);
            this.welcome.setText(end);
            this.create.setText(R.string.save);
            this.create.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    LiveDataBus.getInstance().with("end", String.class).setValue(welcome.getText().toString());
                    finish();
                }
            });
        }
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_add_questionaire_aactivity;
    }

    @Override
    public void init() {
        getNavView().setTitle(R.string.add_questionaire_title).getNav().setBackgroundColor(getColor(R.color.priBlue));
        TextView create = new TextView(A);
        create.setText(R.string.create);
        create.setTextColor(getColor(R.color.white));
        getNavView().getNavRightView().addView(create);
        this.create = create;
        title = (EditText) findViewById(R.id.title2);
        welcome = (EditText) findViewById(R.id.welcome);


        quesTitle = (TextView) findViewById(R.id.ques_title);
        title2 = (EditText) findViewById(R.id.title2);
        welcomeTitle = (TextView) findViewById(R.id.welcome_title);
    }
}